<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Create a gzip compressed string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.gzdeflate.html">gzdeflate</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.gzeof.html">gzeof</a></div>
 <div class="up"><a href="ref.zlib.html">Zlib 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.gzencode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">gzencode</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.4, PHP 5)</p><p class="refpurpose"><span class="refname">gzencode</span> &mdash; <span class="dc-title">Create a gzip compressed string</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.gzencode-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>gzencode</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$level</code><span class="initializer"> = -1</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$encoding_mode</code><span class="initializer"> = FORCE_GZIP</span></span>
  ]] )</div>

  <p class="para rdfs-comment">   
   This function returns a compressed version of the input
   <em><code class="parameter">data</code></em> compatible with the output of the
   <strong class="command">gzip</strong> program.
  </p>
  <p class="para">
   For more information on the GZIP file format, see the document:
   <a href="http://www.faqs.org/rfcs/rfc1952" class="link external">&raquo;&nbsp;GZIP file format specification
   version 4.3</a> (RFC 1952).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.gzencode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">data</code></em></dt>

     <dd>

      <p class="para">
       The data to encode.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">level</code></em></dt>

     <dd>

      <p class="para">
       The level of compression. Can be given as 0 for no compression up to 9
       for maximum compression. If not given, the default compression level will
       be the default compression level of the zlib library.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">encoding_mode</code></em></dt>

     <dd>

      <p class="para">
       The encoding mode. Can be <strong><code>FORCE_GZIP</code></strong> (the default)
       or <strong><code>FORCE_DEFLATE</code></strong>. 
      </p>
      <p class="para">
       Prior to PHP 5.4.0, using <strong><code>FORCE_DEFLATE</code></strong> results in
       a standard zlib deflated string (inclusive zlib headers) after a gzip
       file header but without the trailing crc32 checksum.
      </p>
      <p class="para">
       In PHP 5.4.0 and later, <strong><code>FORCE_DEFLATE</code></strong> generates
       RFC 1950 compliant output, consisting of a zlib header, the deflated
       data, and an Adler checksum.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.gzencode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The encoded string, or <strong><code>FALSE</code></strong> if an error occurred.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.gzencode-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.4.0</td>
       <td>
        <strong><code>FORCE_DEFLATE</code></strong> now generates RFC 1950 compliant
        output.
       </td>
      </tr>

      <tr>
       <td>4.2.0</td>
       <td>
        The <em><code class="parameter">encoding_mode</code></em> parameter was added
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.gzencode-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   The resulting data contains the appropriate headers and data
   structure to make a standard .gz file, e.g.:
   <div class="example" id="example-788">
    <p><strong>Example #1 Creating a gzip file</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">"bigfile.txt"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$gzdata&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">gzencode</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">9</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"bigfile.txt.gz"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"w"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$gzdata</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.gzencode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.gzdecode.html" class="function" rel="rdfs-seeAlso">gzdecode()</a> - Decodes a gzip compressed string</span></li>
    <li class="member"><span class="function"><a href="function.gzdeflate.html" class="function" rel="rdfs-seeAlso">gzdeflate()</a> - Deflate a string</span></li>
    <li class="member"><span class="function"><a href="function.gzinflate.html" class="function" rel="rdfs-seeAlso">gzinflate()</a> - Inflate a deflated string</span></li>
    <li class="member"><span class="function"><a href="function.gzuncompress.html" class="function" rel="rdfs-seeAlso">gzuncompress()</a> - Uncompress a compressed string</span></li>
    <li class="member"><span class="function"><a href="function.gzcompress.html" class="function" rel="rdfs-seeAlso">gzcompress()</a> - Compress a string</span></li>
    <li class="member">
     <a href="http://www.faqs.org/rfcs/rfc1950" class="link external">&raquo;&nbsp;
      ZLIB Compressed Data Format Specification (RFC 1950)
     </a>
    </li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.gzdeflate.html">gzdeflate</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.gzeof.html">gzeof</a></div>
 <div class="up"><a href="ref.zlib.html">Zlib 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
